package com.scqkxx.gamebox.widget;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;

import com.scqkxx.gamebox.R;
import com.scqkxx.gamebox.databinding.DialogMyselfCallBinding;

/**
 * 打电话弹出框
 * Created by hghl on 2017/3/22.
 */

public class MySelfCallDialog {
    private Dialog dialog;
    private Context context;
    private DialogMyselfCallBinding binding;
    private OnConfirmListener onConfirmListener;
//    private String ContentStr = "";
    /**
     * @param context
     */
    public MySelfCallDialog(Context context) {
        this.context = context;
//        ContentStr = str;
        binding = DialogMyselfCallBinding.inflate(LayoutInflater.from(context));
        binding.dialogCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });
        dialog = new Dialog(context, R.style.custom_dialog);// 创建自定义样式dialog
        dialog.setCancelable(true);// 可以用“返回键”取消
        dialog.setCanceledOnTouchOutside(true);// 设置点击屏幕Dialog不消失
        dialog.setContentView(binding.getRoot(), new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));// 设置布局
    }

    public void dismiss() {
        if (dialog.isShowing()) {
            dialog.dismiss();
        }
    }

    public void show(String str,final OnConfirmListener onConfirmListener){
        binding.dialogContent.setText(str);
        binding.dialogSure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(null!=onConfirmListener){
                    onConfirmListener.onSure();
                }
                dismiss();
            }
        });
        dialog.show();
    }

    public interface OnConfirmListener {
        void onSure();
    }
}
